﻿using AutoMapper;
using B.S.BasicData.Api.Write.Applications.Command;
using B.S.BasicData.Domains;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructures;
using MediatR;

namespace B.S.BasicData.Api.Write.Applications.CommandHandler
{
    public class DelPermissonCommandHandler : IRequestHandler<DelPermissonCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<Permissons> permissonsRepository;
        private readonly IMapper mapper;


        public DelPermissonCommandHandler(IBaseRepository<Permissons> permissonsRepository, IMapper mapper)
        {
            this.permissonsRepository = permissonsRepository;
            this.mapper = mapper;
        }

        public async Task<ApiResult<int>> Handle(DelPermissonCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result=new ApiResult<int>();
            result.Code = ApiEnum.Success;
            result.Message = "列表删除成功";
            Permissons permissons = mapper.Map<Permissons>(request);
            permissons.IsDel = true;
            result.data=await permissonsRepository.Update(permissons);
            return await Task.FromResult(result);
        }
    }
}
